home *** CD-ROM | disk | FTP | other *** search
/ HTBasic 9.3 / HTBasic 9.3.iso / 93win / data1.cab / DLL_Toolkit / Source / HTBDde / MFCDDE.H < prev    next >
Encoding:
C/C++ Source or Header  |  2005-03-02  |  6.1 KB  |  234 lines

  1. /////////////////////////////////////////////////////////////////////////////
  2. /*
  3.     File:        mfcdde.h
  4.     Purpose:    MFC DDE classes
  5.     Author:        Julian Smart
  6.  
  7.     Note:
  8.         Minor modifications have been made to the original class by Julian
  9.     Smart.  Along with some formating and slight documentation changes a
  10.     private member variable m_nTimeOut is now used to specifiy the timeout
  11.     for DDE transactions.  A new member funciton SetTimeout can be used to
  12.     set a new timeout value.  This new function also returns the currrent
  13.     timeout value.
  14. */
  15.  
  16.  
  17. #ifndef MFCDDEH
  18. #define MFCDDEH
  19.  
  20. /////////////////////////////////////////////////////////////////////
  21. // Includes
  22. //
  23. #include <ddeml.h>
  24.  
  25. /////////////////////////////////////////////////////////////////////////////
  26. /*
  27.     Mini-Dde implementation
  28.  
  29.     Most transactions involve a topic name and an item name.
  30.  
  31.     A client can:
  32.  
  33.     - ask the server to execute commands (data) associated with a topic
  34.     - request data from server by topic and item
  35.     - poke data into the server
  36.     - ask the server to start an advice loop on topic/item
  37.     - ask the server to stop an advice loop
  38.  
  39.     A server can:
  40.  
  41.     - respond to execute, request, poke and advice start/stop
  42.     - send advise data to client
  43.  
  44.     Note that this limits the server in the ways it can send data to the
  45.     client, i.e. it can't send unsolicited information.
  46. */
  47.  
  48. /////////////////////////////////////////////////////////////////////
  49. // Function Prototypes
  50. //
  51. void DdeInitialize();
  52. void DdeCleanUp();
  53.  
  54. /////////////////////////////////////////////////////////////////////
  55. // Defines
  56. //
  57. #define DEFAULT_TIMEOUT 5000
  58.  
  59. /////////////////////////////////////////////////////////////////////
  60. // Foreward Class Declarations
  61. //
  62. class CDdeServer;
  63. class CDdeClient;
  64.  
  65.  
  66. /////////////////////////////////////////////////////////////////////////////
  67. /*
  68.     Class:        CDdeConnection : public CObject
  69.  
  70.     Description:    
  71.  
  72.     Notes:
  73.         
  74. */
  75. class CDdeConnection : public CObject
  76. {
  77. public:
  78.     long m_nConversationId;
  79.     char *m_pIpcBuffer;
  80.     int m_nIpcBufferSize;
  81.     CString m_sTopicName;
  82.     CDdeServer *m_pServer;
  83.     CDdeClient *m_pClient;
  84.     
  85.     HCONV m_hConv;
  86.     char *m_pSendingData;
  87.     int m_nSendingDataSize;
  88.     int m_nSendingDataType;
  89.     
  90.     CDdeConnection(char *pIpcBuffer, int nIpcBufferSize);
  91.     CDdeConnection(void);
  92.     ~CDdeConnection(void);
  93.     
  94.     /////////////////////////////////////////////////////////////////////
  95.     // Calls that CLIENT can make
  96.     //
  97.     DWORD SetTimeOut(DWORD nTimeOut);
  98.     virtual BOOL Execute(char *pData, int nDataSize = -1, int nFormat = CF_TEXT);
  99.     virtual BOOL Execute(const CString& sData) 
  100.     { 
  101.         return Execute((char *)(const char *)sData, -1, CF_TEXT);
  102.     }
  103.     virtual char *Request(const CString& sItem, int *pnDataSize = NULL, int nFormat = CF_TEXT);
  104.     virtual BOOL Poke(const CString& sItem, char *pData, int nDataSize = -1, int nFormat = CF_TEXT);
  105.     virtual BOOL StartAdvise(const CString& sItem);
  106.     virtual BOOL StopAdvise(const CString& sItem);
  107.     
  108.     /////////////////////////////////////////////////////////////////////
  109.     // Calls that SERVER can make
  110.     //
  111.     virtual BOOL Advise(const CString& sItem, char *pData, int nDataSize = -1, int nFormat = CF_TEXT);
  112.     
  113.     /////////////////////////////////////////////////////////////////////
  114.     // Calls that BOTH can make
  115.     //
  116.     virtual BOOL Disconnect(void);
  117.     virtual void Notify(BOOL bNotify);  // Internal use only
  118.     
  119.     /////////////////////////////////////////////////////////////////////
  120.     // Callbacks to SERVER - override at will
  121.     //
  122.     virtual BOOL OnExecute(const CString& sTopic, char *pData, int nDataSize, int nFormat)
  123.     {
  124.         return FALSE;
  125.     };
  126.     virtual char *OnRequest(const CString& sTopic, const CString& sItem, int *nDataSize, int nFormat)
  127.     {
  128.         return NULL;
  129.     };
  130.     virtual BOOL OnPoke(const CString& sTopic, const CString& sItem, char *pData, int nDataSize, int nFormat)
  131.     {
  132.         return FALSE;
  133.     };
  134.     virtual BOOL OnStartAdvise(const CString& sTopic, const CString& sItem)
  135.     {
  136.         return FALSE;
  137.     };
  138.     virtual BOOL OnStopAdvise(const CString& sTopic, const CString& sItem)
  139.     {
  140.         return FALSE;
  141.     };
  142.     
  143.     /////////////////////////////////////////////////////////////////////
  144.     // Callbacks to CLIENT - override at will
  145.     //
  146.     virtual BOOL OnAdvise(const CString& sTopic, const CString& sItem, char *pData, int nDataSize, int nFormat)
  147.     {
  148.         return FALSE;
  149.     };
  150.     
  151.     /////////////////////////////////////////////////////////////////////
  152.     // Callbacks to BOTH
  153.     //
  154.     
  155.     /////////////////////////////////////////////////////////////////////
  156.     // Default behaviour is to delete connection and return TRUE
  157.     //
  158.     virtual BOOL OnDisconnect(void);
  159.  
  160. private:
  161.     DWORD m_nTimeOut;
  162. };
  163.  
  164.  
  165. /////////////////////////////////////////////////////////////////////////////
  166. /*
  167.     Class:        CDdeObject : public CObject
  168.  
  169.     Description:    
  170.  
  171.     Notes:
  172.         
  173. */
  174. class CDdeObject : public CObject
  175. {
  176. public:
  177.     int lastError;
  178.     CString m_sServiceName; // Server only
  179.     CObList m_Connections;
  180.     
  181.     CDdeObject(void);
  182.     ~CDdeObject(void);
  183.     
  184.     // Find/delete CDdeConnection corresponding to the HCONV
  185.     CDdeConnection *FindConnection(HCONV hConv);
  186.     BOOL DeleteConnection(HCONV hConv);
  187. };
  188.  
  189.  
  190. /////////////////////////////////////////////////////////////////////////////
  191. /*
  192.     Class:        CDdeServer : public CDdeObject
  193.  
  194.     Description:    
  195.  
  196.     Notes:
  197.         
  198. */
  199. class CDdeServer : public CDdeObject
  200. {
  201. public:
  202.     
  203.     CDdeServer(void);
  204.     ~CDdeServer(void);
  205.     BOOL Create(const CString& sServerName);    // Returns FALSE if can't create server (e.g. port
  206.                                                 // number is already in use)
  207.     virtual CDdeConnection *OnAcceptConnection(const CString& sTopic);
  208. };
  209.  
  210.  
  211. /////////////////////////////////////////////////////////////////////////////
  212. /*
  213.     Function:        CDdeClient : public CDdeObject
  214.  
  215.     Description:    
  216.  
  217.     Notes:
  218.         
  219. */
  220. class CDdeClient : public CDdeObject
  221. {
  222. public:
  223.     CDdeClient(void);
  224.     ~CDdeClient(void);
  225.     BOOL ValidHost(const CString& sHostName);
  226.     virtual CDdeConnection *MakeConnection(const CString& sHostName, const CString& sServerName, const CString& sTopic);
  227.                                                     // Call this to make a connection.
  228.                                                     // Returns NULL if cannot.
  229.     virtual CDdeConnection *OnMakeConnection(void); // Tailor this to return own connection.
  230. };
  231.  
  232.  
  233. #endif
  234.